//
// Created by 77873 on 2020/10/10 0010.
//

#ifndef FFMPEGVIDEOPLAYER_DECODEC_H
#define FFMPEGVIDEOPLAYER_DECODEC_H

#include "jni.h"
#include "CallBackToJava.h"
#include "pthread.h"

#include "AudioDecodec.h"
#include "VideoDecodec.h"

extern "C" {
    #include <libavformat/avformat.h>
    #include <libavutil/time.h>
}
/**
 * 解码
 */
class Decodec {

public:
    CallBackToJava *callBackToJava=NULL;
    AudioDecodec *audioDecodec=NULL;
    VideoDecodec *videoDecodec=NULL;
    PlayStatus *playStatus=NULL;


    const char *fileUrl = NULL;
    bool isDecodecFinish = false;//解码是否完成
    int videoDuration = 0;//时长

    pthread_mutex_t init_mutex; //初始化线程锁
    pthread_t threadDecodec;//解码线程

    //decodec
    AVFormatContext *avFormatContext=NULL;

    pthread_mutex_t seekMutex;

    bool  isSupportMediaCodec= false;

    /**
     * 硬解码
     */
    const AVBitStreamFilter *avBitStreamFilter=NULL;


public:

    Decodec(CallBackToJava *callJava,const char *musicUrl,PlayStatus *playStatus);

    ~Decodec();

    void onParpared();

    //解码线程
    void decodeFFmpegThread();

    void start();

    void pause();

    void resume();

    void seek(int64_t second);

    void setVolume(int percnet);

    void setMute(int mute);

    void release();

    int initAvCodecContext(AVCodecParameters *codecParameters,AVCodecContext **currentCodecContext);

    void initErrorRelease();
};


#endif //FFMPEGVIDEOPLAYER_DECODEC_H
